package com.lbxz.ocrapi.response;

import static com.lbxz.ocrapi.constant.ResponseConstants.*;

public class ResponseResult<T>{
    /**
     * 错误码
     */
    private int code;

    /**
     * 错误提示
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    public static ResponseResult success(){
        return new ResponseResult<>(CODE_SUCCESS, MSG_SUCCESS);
    }

    public static ResponseResult success(String msg){
        return new ResponseResult<>(CODE_SUCCESS, msg);
    }

    public static <T> ResponseResult<T> success(T result){
        return new ResponseResult<>(CODE_SUCCESS, MSG_SUCCESS, result);
    }

    public static <T> ResponseResult<T> success(T result, String msg){
        return new ResponseResult<>(CODE_SUCCESS, msg, result);
    }

    public static <T> ResponseResult<T> error(String msg){
        return new ResponseResult<>(CODE_FAIL, msg);
    }

    public static <T> ResponseResult<T> error(int code, String msg){
        return new ResponseResult<>(code, msg);
    }

    public ResponseResult() {
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
